package cc.chenwenxi;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import cc.chenwenxi.iot.PiIotMqtt;
import cn.hutool.core.text.StrFormatter;
import kits.iot.client.entity.DriverInfo;
import lombok.extern.slf4j.Slf4j;

/**
 * 系统启动执行
 */
@Slf4j
@Component // 被spring容器管理
@Order(1) // 如果多个自定义ApplicationRunner，用来标明执行顺序
public class SystemStartRunner implements ApplicationRunner {
	@Override
	public void run(ApplicationArguments applicationArguments) throws Exception {
		String os = System.getProperty("os.name");
		log.info("系统名称:" + os);
		
		String deviceName = "wQjJWpKLYLKanQ7x4aYS";
		String productKey = "a1CGXPQ9VHt";
		String secret = "wW5bAK5BpZSGcmY7FUs9YscURrRQFzz5";
		DriverInfo driverInfo = new DriverInfo().setDeviceName(deviceName).setProductKey(productKey).setDeviceSecret(secret);
		
		String topic = StrFormatter.format("/{}/{}/user/get", driverInfo.getProductKey(), driverInfo.getDeviceName());
		new PiIotMqtt(topic,driverInfo).connect();

		log.info("系统启动完成~~~~~");
	}

}